/*
 * @Author: 代勇 1031850847@qq.com
 * @Date: 2023-11-17 08:53:41
 * @LastEditors: 代勇 1031850847@qq.com
 * @LastEditTime: 2024-03-27 09:53:11
 * @Description: wangEditor编辑器配置
 */

const defaultConfig = {
    placeholder: '请在这里输入内容',
    autoFocus: false,
    MENU_CONF: {
        uploadImage: {
            customUpload: (file, insertFn) => {
                //判断图片大小
                if (file.size > config.upload.imageMaxSize) {
                    const maxSizeTxt = (config.upload.imageMaxSize / 1024 / 1024).toFixed(2) * 100 / 100 + 'M'
                    const fileSizeTxt = (file.size / 1024 / 1024).toFixed(2) * 100 / 100 + 'M'
                    sys.tip({
                        message: '"' + file.name + '" 大小为' + fileSizeTxt + ', 超过了' + maxSizeTxt + '的上传限制。',
                        type: 'warning',
                        grouping: true
                    })
                } else { //开始上传
                    const formData = new FormData();
                    formData.append('image', file);
                    axios.post('/uploads/image', formData).then(response => {
                        if (response.status == 1) {
                            insertFn(response.data.url, response.data.name)
                        } else {
                            sys.tip(response)
                        }
                    })
                }
            }
        },
        uploadVideo: {
            customUpload: (file, insertFn) => {
                //判断视频大小
                if (file.size > config.upload.videoMaxSize) {
                    const maxSizeTxt = (config.upload.videoMaxSize / 1024 / 1024).toFixed(2) * 100 / 100 + 'M'
                    const fileSizeTxt = (file.size / 1024 / 1024).toFixed(2) * 100 / 100 + 'M'
                    sys.tip({
                        message: '"' + file.name + '" 大小为' + fileSizeTxt + ', 超过了' + maxSizeTxt + '的上传限制。',
                        type: 'warning',
                        grouping: true
                    })
                } else { //开始上传
                    const formData = new FormData();
                    formData.append('video', file);
                    axios.post('/uploads/video', formData).then(response => {
                        if (response.status == 1) {
                            insertFn(response.data.url, response.data.poster)
                        } else {
                            sys.tip(response)
                        }
                    })
                }
            }

        }
    }
}
export default defaultConfig
